<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org"
	xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header">

</head>

<body class="gray-bg">
	<div class="wrapper wrapper-content  animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox">
                    <div class="ibox-content">	
                        <div class="clients-list">
                            <ul class="nav nav-tabs">
                                <li class="active"><a data-toggle="tab" href="#tab-1"><i class="fa fa-user"></i> 备案信息</a>
                                </li>
                                <li class=""><a data-toggle="tab" href="#tab-2"><i class="fa fa-briefcase"></i> 会议信息</a>
                                </li>
                            </ul>
                            <br>
                            <div class="tab-content">
                                <div id="tab-1" class="tab-pane active">
                                    <div class="full-height-scroll">
                                        <div class="col-sm-12 col-sm-offset-0">
                                          <div class="panel panel-primary">
                                          	<div class="panel-heading">
                                          		<i class="fa fa-info-circle"></i> 详情
                                          	</div>
                                          	<div class="panel-body">
									            <div class="wrapper wrapper-content animated fadeInUp">
									                <div class="ibox">
									                    <div class="ibox-content">
									                        <div class="row">
									                            <div class="col-sm-12">
									                                <dl class="dl-horizontal">
									                                    <dt>状态：</dt>
									                                    <dd>
									                                    	<span th:if="${officialEvolve.state == 0}" class="label label-warning">等待备案</span>
									                                    	<span th:if="${officialEvolve.state == 1}" class="label label-primary">备案完成</span>
									                                    </dd>
									                                </dl>
									                            </div>
									                        </div>
									                        
									                        <div class="row">
									                            <div class="col-sm-12">
									                            	<div class="col-sm-6">
										                                <dl class="dl-horizontal" th:object="${officialEvolve}">
										                                	
										                                	
										                                    <dt>&nbsp;</dt><dd>&nbsp;</dd>
										                                    <dt>编号：</dt>
										                                    <dd th:id="officialEvolveId" th:value="*{officialEvolveId}" th:text="*{officialEvolveId}">获取失败</dd>
										                                    
										                                    <dt>&nbsp;</dt><dd>&nbsp;</dd>
										                                    <dt>会议名称：</dt>
										                                    <dd th:text="*{conference.conferenceName}">获取失败</dd>
										                                    <dd hidden="hidden" id="conferenceId" th:text="*{conference.conferenceId}"></dd>
										                                    									                                    
										                                </dl>
										                        	</div>
										                        	
										                        	<div class="col-sm-6">
											                        	<dl class="dl-horizontal" th:object="${officialEvolve}">
											                        		<dt>&nbsp;</dt><dd>&nbsp;</dd>
											                        		
											                                    <dt>正式党员名册：</dt>
											                                    <dd>
											                                    	<a>正式党员名册.xls</a>
											                                    	<a th:href="@{/module/proposer/review(userId=*{officialEvolveId},type=officialRoster,fileName=*{officialRoster})}" class="btn btn-success btn-xs fa fa-edit" th:text="预览"></a>
		                                    										<a th:href="@{/module/proposer/download(userId=*{officialEvolveId},type=officialRoster,fileName=*{officialRoster})}" class="btn btn-success btn-xs fa fa-edit" th:text="下载"></a>
											                                    </dd>
											                                    
											                                    <dt>&nbsp;</dt><dd>&nbsp;</dd>
											                                    <dt>提交时间：</dt>
											                                    <dd th:text="*{#dates.format(submitTime,'yyyy-MM-dd')}">获取失败</dd>
											                        	</dl>
										                        	</div>
									                            </div>
															</div>  
															<div class="btn-group hidden-xs" id="toolbar" role="group">
													        	<span>请操作好备案对象后并保存提交</span>
													        </div>
															<div class="row">
									                        	<div class="col-sm-12 select-info order-table">
																    <table id="bootstrap-table" data-mobile-responsive="true"></table>
																</div>
									                        </div>
									                      </div>
									                        
									                        <div class="row">&nbsp;</div>
									                        <div class="row">&nbsp;</div>
									                        <div class="row text-center">
									                        	<a type="button" href="javascript:" onclick="self.location=document.referrer;" class="btn btn-default btn-lg"><i class="fa fa-close"></i>&nbsp;返 回</a>&nbsp;&nbsp;
									                        	<a type="button" href="javascript:" th:if="${officialEvolve.state == 0}" onclick="save()" class="btn btn-primary btn-lg"><i class="fa fa-check"></i>&nbsp;保 存</a>
									                        </div>
									                    </div>
									                </div>
									            </div>
									            <div class="panel-footer">
                                        			面板脚
                                   				</div>
								            </div>
								            
								            
								          </div>
								        </div>
                                </div>
                                
                                <div id="tab-2" class="tab-pane">
                                	o(*￣︶￣*)o 
                                </div>
                                
                            </div>

                        </div>
                    </div>
                </div>
            </div>
  
        </div>
    </div>
	<div th:include="include :: footer"></div>
	<!-- 甜甜的弹出层 -->
 	<script src="https://cdn.bootcss.com/limonte-sweetalert2/7.21.1/sweetalert2.all.js"></script>
	<script th:inline="javascript">
	
		var prefix = "/module/officialEvolve";
		//通过备案记录编号读取备案名单
		var officialEvolveId = [[${officialEvolve.officialEvolveId}]];
		
		$(document).ready(function(){
			queryUserList();
		});
		
		
		
		//提交备案
		function save(){
			//获取到备案的用户id数组
			var proposerList = [[${officialEvolve.prepareList}]]
			var userArray = proposerList.split(",");
			
			//存放通过ID
			var passIdList = '';
			//存放未通过ID
			var notPassList = '';
			//根据备案名单获取到的一一对应的通过与否状态集合
			var state = [];
			
			//根据备案名单获取一一对应的通过与否状态集合
			for(var i = 0; i < userArray.length-1; i++){
				//根据userId获取选中的单选框
				var state = $("input[name="+userArray[i]+"]:checked").val();
				//判断 0通过 1未通过
				if(state == 0){
					passIdList += userArray[i] + ','; 
				}else{
					notPassList += userArray[i] + ',';
				}
			}
			submit(passIdList, notPassList);
		}
		
		//提交名单
		function submit(passList, notPassList){
			$.ajax({
				url: '/module/officialEvolve/saveUserList',
				type: 'post',
				datatype: 'json',
				data: {'successList': passList, 'failList': notPassList, 'officialEvolveId': $('#officialEvolveId').html()
				, 'conferenceId': $('#conferenceId').html()},
				success: function(data){
					if(data.code == 0){
						swal({
							title: '祝贺您',
							text: '备案成功',
							type: 'success'						
						}).then(function(value){
							//返回上一级并刷新
							window.location.href=document.referrer;
						});
					}else{
						swal(
    					"备案失败",
    					"请联系网站管理员",
    					"error"
    				);
					}
				},
				error: function(data){
					swal(
    					"请求失败",
    					"请联系网站管理员",
    					"error"
    				);
				}
			});
		}
		
		function queryUserList() {
				    var options = {
				        url: prefix + "/getRecordsUserList?id="+officialEvolveId+"",
				        createUrl: prefix + "/add",
				        updateUrl: prefix + "/edit/{id}",
				        removeUrl: prefix + "/remove",
				        exportUrl: prefix + "/export",
				        developUrl: prefix + "/develop/{id}",
				        sortName: "createTime",
				        sortOrder: "desc",
				        modalName: "用户",
				        search: false,
				        showExport: false,
				        columns: [
				        {
			                 field: 'id',
			                 title: '序号',
			                 width:10,
			                 align:'center',
			                 switchable:false,
			                 formatter:function(value,row,index){
			                     return index+1;//这样的话每翻一页都会重新从1开始，
			                 }
				        },
				        {
				            field: 'userName',
				            title: '姓名',
				            sortable: true
				        },
						{
							field: 'idCardNo',
							title: '身份证号码',
							align: 'center'
						},
						{
							field: 'proposer.prepareInvestigate',
							title: '预备党员教育考察登记表',
							width: '130px',
							align: 'center',
							formatter: function(value, row, index){
								var content;
								content = 
								'<a class="btn btn-success btn-xs fa fa-edit" href="/module/proposer/review?userId='+ row.userId +'&type=prepareInvestigate&fileName='+ row.proposer.prepareInvestigate +'">预览</a>&nbsp;&nbsp;' +
                                    '<a class="btn btn-success btn-xs fa fa-edit" href="/module/proposer/download?userId='+ row.userId +'&type=prepareInvestigate&fileName='+ row.proposer.prepareInvestigate +'">下载</a>';
								return content;
							}
						},
						{
							field: 'proposer.partyApplicaiton',
							title: '入党志愿书',
							align: 'center',
							formatter: function(value, row, index){
								var content;
								if(value == null){
									content = "无";
								}
								else{
									content = 
									'<a class="btn btn-success btn-xs fa fa-edit" href="/module/proposer/review?userId='+ row.userId +'&type=partyApplicaiton&fileName='+ row.proposer.partyApplicaiton +'">预览</a>&nbsp;&nbsp;' +
                                    '<a class="btn btn-success btn-xs fa fa-edit" href="/module/proposer/download?userId='+ row.userId +'&type=partyApplicaiton&fileName='+ row.proposer.partyApplicaiton +'">下载</a>'+
	                                    	'<a onclick="upload('+ row.userId +')" class="btn btn-primary btn-xs fa fa-edit">提交决议后文件</a>';
								}
								return content;
							}
						},
						{
							field: 'proposer.officialApplication',
							title: '转正申请书',
							width: '130px',
							align: 'center',
							formatter: function(value, row, index){
								var content;
								if(value == null){
									content = "无";
								}else{
								content = 
									'<a class="btn btn-success btn-xs fa fa-edit" href="/module/proposer/review?userId='+ row.userId +'&type=officialApplication&fileName='+ row.proposer.officialApplication +'">预览</a>&nbsp;&nbsp;' +
	                                    '<a class="btn btn-success btn-xs fa fa-edit" href="/module/proposer/download?userId='+ row.userId +'&type=officialApplication&fileName='+ row.proposer.officialApplication +'">下载</a>';
								}
								return content;
							}
						},
						{
							field: 'proposer.prepareToofficialPublicity',
							title: '预备党员转正公示情况登记表',
							width: '130px',
							align: 'center',
							formatter: function(value, row, index){
								var content;
								content = 
								'<a class="btn btn-success btn-xs fa fa-edit" href="/module/proposer/review?userId='+ row.userId +'&type=prepareToofficialPublicity&fileName='+ row.proposer.prepareToofficialPublicity +'">预览</a>&nbsp;&nbsp;' +
	                                    '<a class="btn btn-success btn-xs fa fa-edit" href="/module/proposer/download?userId='+ row.userId +'&type=prepareToofficialPublicity&fileName='+ row.proposer.prepareToofficialPublicity +'">下载</a>';
								return content;
							}
						},
						{
							field: 'proposer.reportFifth',
							title: '思想汇报五',
							width: '130px',
							align: 'center',
							formatter: function(value, row, index){
								var content;
								content = 
								'<a href="/module/proposer/review?userId='+ row.userId +'&type=reportFifth&fileName='+ row.proposer.reportFifth +'" class="btn btn-success btn-xs fa fa-edit">预览</a>&nbsp;&nbsp;' +
                                    '<a href="/module/proposer/download?userId='+ row.userId +'&type=reportFifth&fileName='+ row.proposer.reportFifth +'" class="btn btn-success btn-xs fa fa-edit">下载</a>';
								return content;
							}
						},
						{
							field: 'proposer.reportSixth',
							title: '思想汇报六',
							width: '130px',
							align: 'center',
							formatter: function(value, row, index){
								var content;
								content = 
								'<a href="/module/proposer/review?userId='+ row.userId +'&type=reportSixth&fileName='+ row.proposer.reportSixth +'" class="btn btn-success btn-xs fa fa-edit">预览</a>&nbsp;&nbsp;' +
                                    '<a href="/module/proposer/download?userId='+ row.userId +'&type=reportSixth&fileName='+ row.proposer.reportSixth +'" class="btn btn-success btn-xs fa fa-edit">下载</a>';
								return content;
							}
						},
						{
							field: 'proposer.reportSeventh',
							title: '思想汇报七',
							width: '130px',
							align: 'center',
							formatter: function(value, row, index){
								var content;
								content = 
								'<a href="/module/proposer/review?userId='+ row.userId +'&type=reportSeventh&fileName='+ row.proposer.reportSeventh +'" class="btn btn-success btn-xs fa fa-edit">预览</a>&nbsp;&nbsp;' +
                                    '<a href="/module/proposer/download?userId='+ row.userId +'&type=reportSeventh&fileName='+ row.proposer.reportSeventh +'" class="btn btn-success btn-xs fa fa-edit">下载</a>';
								return content;
							}
						},
						{
							field: 'proposer.reportEighth',
							title: '思想汇报八',
							align: 'center',
							width: '130px',
							formatter: function(value, row, index){
								var content;
								content = 
								'<a href="/module/proposer/review?userId='+ row.userId +'&type=reportEighth&fileName='+ row.proposer.reportEighth +'" class="btn btn-success btn-xs fa fa-edit">预览</a>&nbsp;&nbsp;' +
                                    '<a href="/module/proposer/download?userId='+ row.userId +'&type=reportEighth&fileName='+ row.proposer.reportEighth +'" class="btn btn-success btn-xs fa fa-edit">下载</a>';
								return content;
							}
						},
				        {
				            title: '操作',
				            align: 'center',
				            width: '100px',
				            formatter: function(value, row, index) {
				            	//审批完成
				            	var state = [[${officialEvolve.state}]];
				            	if(state == 1){
				            		//如果角色为积极分子，则视为备案通过
				            		switch(row.roleIds[0]){
				            			case 2:
				            				return "未通过";
				            				break;
				            			//已经通过的人角色可以是积极分子及其上的
				            			default:
				            				return "已通过";
				            				break;
				            		}
				            	}else{
					            	var actions = [];
					                actions.push(
					                	'<label><input value="0" checked th:id='+ row.userId +' name='+ row.userId +' type="radio">通过</label>&nbsp;&nbsp;&nbsp;'+
					                	'<label><input value="1" th:id='+ row.userId +' name='+ row.userId +' type="radio"><i></i> 未通过</label>'
					                );
			 		                return actions.join('');
				            	}
				            }
				        }]
				    };
				    $.table.init(options);
				}
	</script>
	<script>
	
		//上传修改后的发展对象备案登记表
		function upload(userId){
			swal({
		  title: '提交文件',
		  input: 'file',
		    inputAttributes: {
    			accept: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/msword'
  			},
		  showCancelButton: true,
		  confirmButtonText: '确认提交',
		  showLoaderOnConfirm: true,
		  //提交前函数
		  preConfirm: function(file) {
		  	//校验函数
		    return new Promise(function(resolve, reject) { //返回resolve()为通过，reject()拒绝
		      //校验是否为doc或者docx
		        if (file.type === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' || value.type === 'application/msword') {
		          resolve();
		        } else {
		            swal(
				    '文件格式不正确！',
				    '只能上传docx类型的文件',
				    'warning'
				  ); 
		        }
		    });
		  },
		  allowOutsideClick: false
		}).then(	//接着执行
		   function (file) {
		   //如果没有传入文件，而是点击取消，则不采取操作
		   if(file.value == undefined){
				return;		   
		   }
		   var fm = new FormData();
		   fm.append("file", file.value);
		   fm.append("userId", userId);
		   fm.append("type", 'partyApplicaiton')
		   $.ajax({
		   		url: '/module/proposer/materials/upload',
		   		type: 'post',
		   		data: fm,
		   		dataType: 'json',
		   		contentType: false, //禁止设置请求类型
           		processData: false, //禁止jquery对DAta数据的处理,默认会处理
            	//禁止的原因是,FormData已经帮我们做了处理
		   		success: function(result){
		   			if(result.code === 0){
		   				swal(
						  '一切顺利',
						  result.msg,
						  'success'
						).then(function(){
							//刷新页面
							//window.location.reload();
						});
						
		   			} else{
		   				swal(
						  '抱歉',
						  result.msg,
						  'error'
						)
		   			}
		   		},
		   		error: function(result){
		   				swal(
						  '抱歉',
						  '请求失败，请于网站管理员联系',
						  'error'
						)
		   		}
		   });
		}
		);
		}
	</script>
</body>
</html>